package cc.sunwl.study.springboot.demo.gson.service.impl;

import cc.sunwl.study.springboot.demo.gson.entity.Article;
import cc.sunwl.study.springboot.demo.gson.mapper.ArticleMapper;
import cc.sunwl.study.springboot.demo.gson.service.ArticleService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public Article get(String id) {
        return articleMapper.selectByPrimaryKey(id);
    }

    @Override
    public boolean post(Article entity) {
        int insert = articleMapper.insert(entity);
        return insert > 0;
    }

    @Override
    public boolean delete(String id) {
        int i = articleMapper.deleteByPrimaryKey(id);
        return i > 0;
    }

    @Override
    public boolean put(Article entity) {
        int i = articleMapper.updateByPrimaryKeySelective(entity);
        return i > 0;
    }

    @Override
    public List<Article> findAll(int page, int size) {
        PageHelper.startPage(page, size);
        return articleMapper.selectAll();
    }
}
